package com.qyhl.module_practice.rank.team;

import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeTeamBean;

import java.util.List;

public class PracticeTeamRankModel implements PracticeTeamRankContract.PracticeTeamRankModel {
    private PracticeTeamRankPresenter mPresenter;

    PracticeTeamRankModel(PracticeTeamRankPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String page, int type) {
        String url = "";
        switch (type) {
            case 1:
                url = PracticeUrl.GET_PRACTICE_TEAM_LIST_BY_TIME;
                break;
            case 2:
                url = PracticeUrl.GET_PRACTICE_TEAM_LIST_BY_ACT;
                break;
            case 3:
                url = PracticeUrl.GET_PRACTICE_TEAM_LIST_BY_PERSON;
                break;
        }

        EasyHttp.get(url)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeTeamBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何服务队！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取列表失败，请重新尝试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeTeamBean> practiceTeamBeans) {
                        if (practiceTeamBeans != null && practiceTeamBeans.size() > 0) {
                            mPresenter.setList(practiceTeamBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何服务队！", !page.equals("1"));
                        }
                    }
                });
    }
}
